package main

import (
	"fmt"
	"sync"
	"time"
)

func main1() {
	var wg sync.WaitGroup

	wg.Add(3)
	go func() {
		defer wg.Done()
		fmt.Println("1")
	}()
	go func() {
		defer wg.Done()
		fmt.Println("2")
	}()
	go func() {
		defer wg.Done()
		fmt.Println("3")
	}()
	wg.Wait()
}

func main() {
	var wg sync.WaitGroup
	now := time.Now()
	for i := 0; i < 10; i++ {
		wg.Add(1)
		go work(&wg, i)
	}
	wg.Wait()
	fmt.Println("main is done in ", time.Since(now))

}

func work(wg *sync.WaitGroup, i int) {
	defer wg.Done()
	time.Sleep(100 * time.Millisecond)
	fmt.Printf("work %d has been done\n", i)
}
